window.onload = function(){
	var gname = document.getElementById("goods_name");
	var gtype = document.getElementById("goods_type");
	var gprice= document.getElementById("goods_price");
	var gtable =document.getElementById("goods_AlterTable");
	
	alert("OK");
	
	gname.onkeyup =function(){
		var name = gname.value.trim();
		var re_gname = /^[a-zA-Z0-9\u4e00-\ugfa5]{1,20}$/g;
		if(name!=""){
			if(re_gname.test(name)){
				console.log("OK");
			}else{
				console.log("NO");
			}
		}else{
			alter("商品名不能为空！");
		}
		
	}
	gtype.onkeyup =function(){
		var type = gtype.value.trim();
		var re_gtype = /^[\u4e00-\ugfa5]{1,10}$/g;
		if(type!=""){
			if(re_gtype.test(type)){
				console.log("OK");
			}else{
				console.log("NO");
			}
		}else{
			alter("商品类型不能为空！");
		}
		
	}
	gprice.onkeyup =function(){
		var price = gprice.value.trim();
		var re_price = /^[0-9.]{1,5}$/g;
		if(price!=""){
			if(re_price.test(price)){
				console.log("OK");
			}else{
				console.log("NO");
			}
		}else{
			alter("商品价格不能为空！");
		}
		
	}
	
	gtable.onsubmit=function(){
		var name = gtable.elements["gname"].value.trim();
		var type = gtable.elements["gtype"].value.trim();
		var price = gtable.elements["gprice"].value.trim();
		
		var re_gname=/^[0-9a-zA-Z\u4e00-\ugfa5]{1,20}$/g;
		var re_gtype=/^[\u4e00-\ugfa5]{1,10}$/g;
		var re_gprice=/^[0-9.]{5}$/g;
		
		if(name!="" && type!="" && price!=""){
			if(re_gname.test(name) && re_gtype.test(type) && re_gprice.test(price)){
				alert("修改成功！");
				return true;
			}else{
				alert("所填项必须合法！");
				return false;
			}
		}else{
			alert("所填项不能为空！");
			return false;
		}
	}
	
}